import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-15
 * Time: 22:08
 */
//https://leetcode.cn/problems/3sum/
public class Test {
    public static List<List<Integer>> threeSum(int[] arr) {
        List<List<Integer>> lists=new ArrayList();
        Arrays.sort(arr);
        int i,j,k,n=0,kk=-1;
        for(i=0;i<arr.length-2;i++){
            if(arr[i]>0){
                continue;
            }
            if(i>0&&arr[i]==arr[i-1]){
                continue;
            }
            j=i+1;
            k=arr.length-1;
            n=0;
            while(j<k){
                if(arr[j]+arr[k]+arr[i]>0){
                    k--;
                }
                else if(arr[j]+arr[k]+arr[i]<0){
                    j++;
                }
                else if(arr[k]!=kk||n==0){
                    List list=new ArrayList();
                    list.add(arr[i]);
                    list.add(arr[j]);
                    list.add(arr[k]);
                    lists.add(list);
                    kk=arr[k];
                    j++;k--;n++;
                }
                else{
                    j++;k--;
                }
            }
        }
        return lists;
    }

    public static void main(String[] args) {
        int[] arr={0,0,0,0};
        List list=threeSum(arr);
        System.out.println(list.toString());
    }
}
